package com.thor.palmmall.dao.unifyversion;

import java.util.List;

import javax.persistence.Query;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.thor.dao.BasicDao;
import com.thor.palmmall.rest.unifyversion.UIpapk;
import com.thor.palmmall.rest.unifyversion.UIpapkType;

@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
public class UIpapkDaoImpl extends BasicDao implements UIpapkDao {

  @Override
  public UIpapk getVersionInfo(UIpapkType type, String authCode, String version) {

    Query query = em.createQuery(
        "from " + PUIpapk.class.getName() + " o where o.type = :type and o.authCode = :authCode");
    query.setParameter("type", type);
    query.setParameter("authCode", authCode);

    List<PUIpapk> list = query.getResultList();
    if (list.isEmpty())
      return null;
    PUIpapk puipapk = list.get(0);
    return new UIpapkConverter().convert(puipapk);

  }
}
